/*
 * SdlVideoWindow.h
 *
 *  Created on: 2016年5月17日
 *      Author: terry
 */

#ifndef SDLVIDEOWINDOW_H_
#define SDLVIDEOWINDOW_H_

#include "VideoWindow.h"
#include "SdlEventManager.h"
#include "SdlPresenter.h"
#include "TCriticalSection.h"
#include "SdlSurfacePtr.h"
#include "AVFramePtr.h"

namespace av
{

class SdlVideoWindow: public VideoWindow, public sdl::EventHandler
{
public:
    enum WindowEvent
    {
        USEREVENT_DRAW_FRAME = SDL_USEREVENT + 1
    };

public:
	SdlVideoWindow();
	virtual ~SdlVideoWindow();

	virtual int open(void* hwnd);
	virtual void close();
	virtual bool isOpen();

	virtual void setVideoWnd(void* hwnd);

	virtual void setState(StreamState state);

	virtual bool draw(AVFrame* frame);

	virtual bool isFullscreen();

	virtual bool setFullscreen(bool full);

	virtual bool setRatio(int width, int height);

	virtual void getRatio(int& width, int& height);

	virtual void setVisible(bool visible);

	virtual bool setBackImage(const char* filepath);

	virtual void flush();

protected:
	virtual void handleEvent(SDL_Event& event);


protected:
    void invalidate();

    void drawFrame();
	void drawFrame(AVFrame* pFrame);
	void drawBackground(bool drawImage);

	//void putIntoWindow(void* hwnd);
	//bool resizeToWindow(void* hwnd);

    void updateRender();
    void fetchFrame();

private:
    comn::CriticalSection   m_cs;
	sdl::EventManagerPtr	m_eventManager;
	SDL_Window*	m_window;
	Uint32	m_winID;
	void*	m_parentWnd;
	StreamState	m_state;
    int     m_ratioX;
    int     m_ratioY;

    AVFramePtr m_backFrame;
    AVFramePtr m_curFrame;

    SDL_Renderer*   m_renderer;
    sdl::Presenter	m_presenter;
    sdl::SurfacePtr    m_backImage;

};



} /* namespace av */

#endif /* SDLVIDEOWINDOW_H_ */
